//二级城市
function changeProvince(obj) {
	$("#areaSpan").empty();
	//省ID
	var parentId = $(obj).val();
	var parentName = $(obj).find("option:selected").text();
	$("#provinceId").attr("value", parentName);
	$("#provinceId").attr("title", parentId);
	//移除省、市的areCity2样式
	$("#provinceSpan").attr("class", "areCity");
	$("#citySpan").attr("class", "areCity");
	$("#citySpan").attr("style", "float:right;");
	$.ajax({
		url: "weiListSecondCityByParentId.jhtml",
		type: "GET",
		data: {parentId: parentId},
		dataType: "json",
		cache: false,
		success: function(data) {
			//alert(JSON.stringify(data.allCitys));
			if(JSON.stringify(data.allCitys) != "[]") {
				$("#cityId").attr("value", "选城市");
				var secondCityOption = '<option value="">选城市</option>';
				$.each(data.allCitys, function(idx, item){
					secondCityOption += '<option  value="'+ item.id +'">'+ item.name +'</option>';
				});
				$("#secondCity").empty().append(secondCityOption);
			}
		}
	});
}

//三级地区
function changeCity(obj) {
	//所选城市
	var cityId = $(obj).val();
	var cityName = $(obj).find("option:selected").text();
	$("#cityId").attr("value", cityName);
	$("#cityId").attr("title", cityId);
	$.ajax({
		url: "weiListThreeCityByParentId.jhtml",
		type: "GET",
		data: {cityId: cityId},
		dataType: "json",
		cache: false,
		success: function(data) {
			if(JSON.stringify(data.allAreas) != "[]") {
				//区不为空时添加省、市的areCity2样式
				$("#provinceSpan").attr("class", "areCity areCity2");
				$("#citySpan").attr("class", "areCity areCity2");
				$("#citySpan").attr("style", "");
				$("#areaSpan").attr("class", "areCity areCity2");
				var areaInput = '<input type="text" value="选地区" class="inpTxta" id="areaId" style="padding:0 1em; height:3em;">'+
				                '<i class="icona03">下箭头</i>'+
				                '<select id="areaForCity" onchange="changeArea(this);">'+
				                '<option value="">选地区</option>';
				$.each(data.allAreas, function(idx, item){
					areaInput += '<option  value="'+ item.id +'">'+ item.name +'</option>';
				});
				areaInput += '</select>';
				$("#areaSpan").empty().append(areaInput);
			}
		}
	});
}

//选地区
function changeArea(obj) {
	var areaName = $(obj).find("option:selected").text();
	$("#areaId").attr("value", areaName);
	$("#areaId").attr("title", $(obj).val());
}
//保存用户信息
function savaUserInfo() {
	//alert($("#memberGender").find("span").attr("title"));
	var memberEmail = $("#memberEmail").attr("value");
	var memberName = $("#memberName").attr("value");
	var memberGender = $("#memberGender").find("span").attr("title");
	var memberBirth = $("#memberBirth").attr("value");
	var provinceId = $("#provinceId").attr("title");
	var cityId = $("#cityId").attr("title");
	var memberAddress = $("#memberAddress").attr("value");
	memberAddress = encodeURI(memberAddress);
	memberAddress = encodeURI(memberAddress);
	var selectAreaId = '';
	if($("#areaP").find("span").length == 3){
		if($("#areaSpan").html().trim() != ""){
			selectAreaId += $("#areaId").attr("title");
		}else{
			selectAreaId += "";
		}
	}
	window.location.href = "saveUserInfo.jhtml?memberEmail="+ memberEmail +"&memberName="+ memberName +"&memberGender="+ memberGender +
	"&memberBirth="+ memberBirth +"&provinceId="+ provinceId +"&cityId="+ cityId +"&areaId="+ selectAreaId +"&memberAddress="+ memberAddress +"";
}




